﻿using BasicInformationCommon.API.BasicInformationCommons.DropDownCommon.ClientTypeRead;
using BasicInformationCommon.API.BasicInformationCommons.DropDownCommon.MaterialRead;
using BasicInformationCommon.API.BasicInformationCommons.Suppliers;
using ERPSystem.Common.Domains.supplier;
using ERPSystem.Common.DTO;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace BasicInformationCommon.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SuppliersController : ControllerBase
    {
        private readonly IMediator _mediator;

        public SuppliersController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 供应商显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        [HttpGet]
        public async Task<ResultPage<SuppliersDTO>> SuppliersList([FromQuery] SuppliersSearchCommand request, CancellationToken cancellationToken)
        {
            var result = await _mediator.Send(request);
            return result;
        }
        /// <summary>
        /// 查询物料分类
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> MaterialList([FromQuery] MaterialReadCommand request, CancellationToken cancellationToken)
        {
            var result = await _mediator.Send(request);
            return result;
        }
        /// <summary>
        /// 采购订单显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<PageResultDto<PurchaseOrderDTO>>> PurchaseOrderList([FromQuery] PurchaseOrderCommand request, CancellationToken cancellationToken)
        {
            var result = await _mediator.Send(request);
            return result;
        }
        /// <summary>
        /// 采购到货订单显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<PageResultDto<PurchasedGoodsDTO>>> PurchasedGoodsList([FromQuery] PurchasedGoodsCommand request, CancellationToken cancellationToken) 
        {
            var result = await _mediator.Send(request);
            return result;
        }
        /// <summary>
        /// 采购订单导出
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ShoppingExcelHandle([FromQuery] PurchaseOrderDaoCommand request)
        {
            var result = await _mediator.Send(request);
            return File(result.FileBytes, result.MimeType, result.FileName);

        }
        /// <summary>
        /// 采购订单反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<PurchaseOrder>> PurchaseOrderFindHandle([FromQuery] PurchaseOrderFindCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request);
        }
        /// <summary>
        /// 采购到货单反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> PurchaseGoodsHandle([FromQuery] PurchaseGoodsFindCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request);
        }
    }
}
